package rsj.job.statistic;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

import static rsj.api.org.importdata.ImportEasyExcelInvoke.IS_COST;

/**
 * 定时统计生产产品使用情况
 *
 * @author yuanqinglong
 * @since 2021/3/9 18:09
 */
@Deprecated
@Component
public class StatisticProductUsage  {





    /**
     * 统计产品使用量SQL语句
     *
     * @param statisticsDate 统计日期
     * @param orgId          统计机构id
     * @return SQL
     */
    public String statisticalSqlStatement(LocalDate statisticsDate, String orgId) {
        String orgCondition = StringUtils.isBlank(orgId) ? "" : " AND org_id = '" + orgId + "'";
        String dateZone = "(log_storagetime < '" + statisticsDate + "' AND log_storagetime >= '" + statisticsDate.minusDays(1) + "')";
        return " SELECT log_prod_uid ,prod_name ,COUNT(*) AS stat_useamount, " +
                " log_orgp_id,org_id,org_sname,log_storagetime::DATE as log_storagetime " +
                " FROM sys.oper_log LEFT JOIN sys.sys_prod ON prod_uid = log_prod_uid " +
                " LEFT JOIN sys.sys_orgp orgp ON orgp.orgp_id =log_orgp_id LEFT JOIN sys.sys_org ON org_id = orgp.orgp_org_id " +
                " WHERE  log_iscost ='" + IS_COST + "' AND " + dateZone + orgCondition +
                " GROUP BY log_orgp_id,log_prod_uid,prod_name,org_id,org_sname,log_storagetime::DATE; ";
    }


}
